[−][src]Crate color_spantrace
A rust library for colorizing tracing_error::SpanTrace
objects in the style
of color-backtrace
.
Setup
Add the following to your Cargo.toml
:
[dependencies]
color-spantrace = "0.1"
tracing = "0.1.13"
tracing-error = "0.1.2"
tracing-subscriber = "0.2.5"
Setup a tracing subscriber with an ErrorLayer
:
use tracing_error::ErrorLayer; use tracing_subscriber::{prelude::*, registry::Registry}; Registry::default().with(ErrorLayer::default()).init();
Create spans and enter them:
use tracing::instrument; use tracing_error::SpanTrace; #[instrument] fn foo() -> SpanTrace { SpanTrace::capture() }
And finally colorize the SpanTrace
:
use tracing_error::SpanTrace; let span_trace = SpanTrace::capture(); println!("{}", color_spantrace::colorize(&span_trace));
Output Format
Running examples/usage.rs
from the color-spantrace
repo produces the following output:
❯ cargo run --example usage Finished dev [unoptimized + debuginfo] target(s) in 0.04s Running `target/debug/examples/usage` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SPANTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0: usage::two at examples/usage.rs:18 1: usage::one with i=42 at examples/usage.rs:13
Structs
InstallThemeError | An error returned by |
Theme | A struct that represents theme that is used by |
Functions
colorize | Display a |
set_theme | Sets the global theme. |